<template>
    <div class="login">
        <div class="img">
            <img src="../../assets/img/login.png" alt="">
        </div>
        <p>登录</p>
        <div class="detail">
            <input type="text" placeholder="请输入手机号" v-model="phone">
            <div class="pwd">
                <input type="text" placeholder="请输入密码" v-model="password">
                <p>忘记密码</p>
            </div>
        </div>
        <!-- <input type="button" value="登录"> -->
        <div class="footer">
            <button type="button" class="green"  @click="goLogin">登录</button>
        <button type="button" @click="goRegister">注册</button>
        </div>
    </div>
</template>

<script>
import {fapi}from'../../assets/js/farmapi.js'
export default {
    data(){
        return{
        password: null,
        phone: null,
        }
    },
    methods:{
          goLogin() {
      fapi("api/login", { phone: this.phone, password: this.password }).then(
        (res) => {

            if(res.data.code ==1){
                Toast.fail(res.data.msg);
                this.$router.push('/register')
            }else{

                localStorage.setItem("islogin",res.data.usermsg.userId);
                 sessionStorage.setItem("islogin",res.data.usermsg.userId);
                sessionStorage.setItem("isnike", res.data.usermsg.nikeName);
                sessionStorage.setItem("isimg", res.data.usermsg.user_img);
               
                this.$router.push('/my')
            }
        }
      )
      
    },goRegister(){
        this.$router.push('/register')
    }
    },
}
</script>

<style lang="less" scoped>
@import url(../../assets/css/coom.css);
    .login{
        width: 100%;
        padding:20px 40px;
       
    }
    img{
        width: 220px;
        height: 250px;
        margin-left: 50%;
        transform: translateX(-50%-20px);

    }
    .img{
        width: 100%;
         
    }
    input{
        width: 80%;
        height: 80px;
        line-height: 80px;
        margin-top: 60px;
        border-bottom:1px solid rgba(0,0,0,0.1);
        font-size: 12px;
    }
    button{
        width: 80%;
        height: 80px;
        border-radius: 30px;
        margin-left:20px;
        margin-top: 30px;
    }
    .green{
        background-color:rgb(0, 162, 153) ;
        color:#fff;
    }
.pwd{
    position: relative;
    z-index: 2;
}
.pwd p{
    display: inline-block;
    width: 100px;
    height: 20px;
    position: absolute;
    font-size: 16px;
    bottom:20px;
    right:100px;
}
.footer{
    margin-top: 50px;
}
</style>